package com.homeparking.manage.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.homeparking.common.annotation.Anonymous;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.homeparking.common.annotation.Log;
import com.homeparking.common.core.controller.BaseController;
import com.homeparking.common.core.domain.AjaxResult;
import com.homeparking.common.enums.BusinessType;
import com.homeparking.manage.domain.ManageParking;
import com.homeparking.manage.domain.OutManageParking;
import com.homeparking.manage.service.IManageParkingService;
import com.homeparking.common.utils.poi.ExcelUtil;
import com.homeparking.common.core.page.TableDataInfo;

/**
 * 车位管理Controller
 * 
 * @author liuyangyang
 * @date 2025-10-16
 */
@RestController
@RequestMapping("/manage/manage_parking")
public class ManageParkingController extends BaseController
{
    @Autowired
    private IManageParkingService manageParkingService;

    /**
     * 查询车位管理列表公共
     */
    @Anonymous
    @GetMapping("/common/list")
    public TableDataInfo list(OutManageParking outManageParking)
    {
        startPage();
        List<OutManageParking> list = manageParkingService.selectManageParkingListCommon(outManageParking);
        return getDataTable(list);
    }

    /**
     * 查询车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_parking:list')")
    @GetMapping("/list")
    public TableDataInfo list(ManageParking manageParking)
    {
        startPage();
        List<ManageParking> list = manageParkingService.selectManageParkingList(manageParking);
        return getDataTable(list);
    }

    /**
     * 导出车位管理列表
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_parking:export')")
    @Log(title = "车位管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ManageParking manageParking)
    {
        List<ManageParking> list = manageParkingService.selectManageParkingList(manageParking);
        ExcelUtil<ManageParking> util = new ExcelUtil<ManageParking>(ManageParking.class);
        util.exportExcel(response, list, "车位管理数据");
    }

    /**
     * 获取车位管理详细信息
     */
    @GetMapping(value = "/{parkingId}")
    public AjaxResult getInfo(@PathVariable("parkingId") Long parkingId)
    {
        return success(manageParkingService.selectManageParkingByParkingId(parkingId));
    }

    /**
     * 新增车位管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_parking:add')")
    @Log(title = "车位管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ManageParking manageParking)
    {
        return toAjax(manageParkingService.insertManageParking(manageParking));
    }

    /**
     * 修改车位管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_parking:edit')")
    @Log(title = "车位管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ManageParking manageParking)
    {
        return toAjax(manageParkingService.updateManageParking(manageParking));
    }

    /**
     * 删除车位管理
     */
    @PreAuthorize("@ss.hasPermi('manage:manage_parking:remove')")
    @Log(title = "车位管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{parkingIds}")
    public AjaxResult remove(@PathVariable Long[] parkingIds)
    {
        return toAjax(manageParkingService.deleteManageParkingByParkingIds(parkingIds));
    }
}
